﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucVote.ascx.cs" Inherits="Controls_ucVote" %>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Button1").click(function () {
            if ($("#hdfAllow").val() != "-1")
                return;
            var hdf = document.getElementById("hdfSelected");
            var form = document.getElementById("aspnetForm");
            if (form) {
                for (var i = 0; i < form.<%=rblVote.ClientID.Replace("_","$") %>.length; i++) {
                    if (form.<%=rblVote.ClientID.Replace("_","$") %>[i].checked) {
                        hdf.value = i.toString();
                        break;
                    }
                }
                if (hdf.value == "-1") {
                    alert('Xin hãy lựa chọn trước khi gửi!');
                    return false;
                }
            }
            $.ajax({
                type: "POST",
                url: "../services/Vote.asmx/sendVote",
                data: "{'index':'" + hdf.value + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function() {
                $("#vote_process").html("<img src=\"../Images/LoadingImg.gif\" />");
                },
                success: function (message) {
                    if (message.d == false) {
                        alert("Máy chủ quá tải mong bạn bầu chọn sau!");
                    }
                    else {
                        $("#hdfAllow").val("1");
                        alert("Bạn đã bầu chọn! Cảm ơn!");
                        $("#vote_process").html("");
                    }
                },
                error: function (errormessage) {
                    alert("Máy chủ quá tải mong bạn bầu chọn sau!");
                }
            });
        });
    });
    function vote() {
        width = 750;
        height = 250;
        left = (screen.width / 2) - width / 2;
        wtop = (screen.height / 2) - height / 2;
        styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=0,copyhistory=yes,width=' + width + ',height=' + height + ',left=' + left + ',top=' + wtop + ',screenX=' + left + ',screenY=' + wtop;
        hearingWindow = window.open("../pages/voteresult.aspx", "Rt24hHearingWindow", styleStr);
        hearingWindow.focus();
    }
</script>
<input type="hidden" value="-1" id="hdfSelected" />
<input type="hidden" value="-1" id="hdfAllow" />
<div class="vote">
    <div class="header">
    </div>
    <div class="vote_content">
        <p class="question" id="divQuesion" runat="server">
        </p>
        <asp:RadioButtonList ID="rblVote" runat="server">
        </asp:RadioButtonList>
        <%--<input id="Button1" class="btnvote" type="button" />--%>
        <%--<a class="poll-result" href="#" onclick="vote();"></a>--%>
        <div class="tdyk-submit clearfix">
            <a class="tdyk-bq" href="javascript:void(0)" id="Button1">Biểu quyết</a> <a class="tdyk-xkq"
                onclick="vote();return false" href="javascript:void(0)">Xem kết quả</a><span id="vote_process"></span>
        </div>
    </div>
</div>
